package main.common.strategy.impl;

import main.common.strategy.DiscountStrategy;

public class NoDiscountStrategy implements DiscountStrategy {
    //单例模式
    private static volatile NoDiscountStrategy instance;

    private NoDiscountStrategy() {
        //防止反射调用构造器
        if(instance != null) {
            throw new RuntimeException("单例模式失败");
        }
    }

    public static NoDiscountStrategy getInstance() {
        if(instance == null) {
            synchronized(NoDiscountStrategy.class) {
                if(instance == null) {
                    instance = new NoDiscountStrategy();
                }
            }
        }
        return instance;
    }
    //防止反序列化
    protected NoDiscountStrategy readResolve() {
        return instance;
    }

    @Override
    public double applyDiscount(double total) {
        return total;
    }
}
